package controlLayer;
import java.util.Scanner;
import modelLayer.Person;
import modelLayer.PersonContainer;

public class PersonCtrl
{
    private Person person;
    private Person newPerson;
    private PersonContainer personContainer;
    public PersonCtrl()
    {
        person = new Person();
        personContainer = PersonContainer.getInstance();
    }

    public boolean findPerson(String searchTerm)
    {
        return personContainer.findPerson(searchTerm);
    }
    
    public Person getPerson(String searchTerm)
    {
        return personContainer.getPerson(searchTerm);
    }
    
    public boolean deletePerson(String searchTerm)
    {
        return personContainer.deletePerson(searchTerm);
    }
    
    public boolean createPerson(String name, String address, String postalCode, String city, String phone)
    {
        return personContainer.createPerson(name, address, postalCode, city, phone);
    }
    
    public boolean updatePerson(String searchTerm)
    {
        boolean updated = false;
        if (personContainer.getPerson(searchTerm) != null)
        {
            System.out.print('\u000C');
            System.out.println("*** Updating Person ***");
            Scanner keyboard = new Scanner(System.in);
            System.out.println("Please enter name:");
            String name = keyboard.next();
            System.out.println("Please enter address:");
            String address = keyboard.next();
            System.out.println("Please enter postal code:");
            String postalCode = keyboard.next();
            System.out.println("Please enter city:");
            String city = keyboard.next();
            System.out.println("Please enter phone number:");
            String phoneNumber = keyboard.next(); 
            updated = updatePersonNow(searchTerm, name, address, postalCode, city, phoneNumber);
        }
        else
       {
           System.out.println("person not found");
       }
       return updated;
    }
    
    
    public boolean updatePersonNow(String searchTerm, String name, String address, String postalCode, String city, String phoneNumber)
    {
        return personContainer.updatePerson(searchTerm, name, address, postalCode, city, phoneNumber);
    }
}
